package com.itoffer.web.old;

import com.itoffer.pojo.Applicant;
import com.itoffer.pojo.ResumeBasicInfo;
import com.itoffer.service.ResumeService;
import com.itoffer.service.impl.ResumeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 修改时回显数据
 */
//@WebServlet("/selectCurrentResumeServlet2")
public class SelectCurrentResumeServlet2 extends HttpServlet {
    private ResumeService resumeService = new ResumeServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //通过applicant_id查询当前对象所持有的basicinfo_id
        //获取session对象中的applicant
        HttpSession session = req.getSession();
        Applicant applicant =(Applicant)session.getAttribute("applicant");

        //测试
        System.out.println(applicant);

        int applicant_id = applicant.getApplicant_id();

        //调用业务层方法来查询
        int basicinfo_id = resumeService.selectBasicinfo_idByApplicant_id(applicant_id);

        //调用查询资料的方法
        ResumeBasicInfo basicInfo = resumeService.selectCurrentResume(basicinfo_id);

        //测试
        System.out.println(basicInfo);

        if(basicInfo!=null){
            req.setAttribute("basicInfo",basicInfo);
            req.getRequestDispatcher("/applicant/resumeBasicinfoUpdate.jsp").forward(req,resp);
        }else{
            //如果查无此人，先暂时让它为空，以后修改
            String contextPath = req.getContextPath();
            resp.sendRedirect(contextPath+"/error.jsp");
        }



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
